package io.github.shang11925.sbvuewelearn.controller;

import io.github.shang11925.sbvuewelearn.dto.VideoResourcesDTO;
import io.github.shang11925.sbvuewelearn.entity.VideoResources;
import io.github.shang11925.sbvuewelearn.response.VideoResourcesResponse;
import io.github.shang11925.sbvuewelearn.service.VideoResourcesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@RestController
@CrossOrigin("http://localhost:5173/")
public class VideoResourcesController {
    @Autowired
    VideoResourcesService videoResourceService;

    @GetMapping("/list-video_resources/{sectionId}")
    public VideoResourcesResponse list(@PathVariable Long sectionId){
        List<VideoResources> videoResources = videoResourceService.findBySectionId(sectionId);
        VideoResourcesResponse videoResourcesResponse = new VideoResourcesResponse();
        videoResourcesResponse.setVideoResources(videoResources);
        return videoResourcesResponse;
    }

    // 创建视频资源（不含文件）
    @PostMapping("/add-video_resources")
    public void add(@RequestBody VideoResourcesDTO videoResourcesDTO,MultipartFile file) throws IOException {
        videoResourceService.uploadCover(file,videoResourcesDTO);
        videoResourceService.add(videoResourcesDTO);
    }

}


